/**
 * 静态方法，接收一个可迭代的promise对象，返回一个promise
 * 当任一个promise被fulfilled，返回的promise也是fulfilled，
 * 所有的promise式rejected，则返回的promise也是rejected，并且带有一个AggregateError数组存所有promise被rejected的reason
 * 传入空对象也返回rejected的promise
 * @param {*} promiseList 
 * @returns 
 */
function promiseAny(promiseList) {
    return new Promise((resolve, reject) => {
        if(!promiseList.length) {
            reject(AggregateError('promiseList must be not empty'));
            return;
        }

        let count = 0;
        const result = Array(promiseList.length);
        promiseList.forEach((promise, index) => {
            Promise.resolve(promise)
            .then(resolve)
            .catch((error) => {
                result[index] = AggregateError(error);
                count++;
                if (count === promiseList.length) {
                    reject(result);
                }
            })
        });
    });
}